<!DOCTYPE HTML>
<html>
<head>
    <title>轮播图列表</title>
    <meta charset="utf-8">
    <meta name="renderer" content="webkit|ie-comp|ie-stand">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport"
          content="width=device-width,initial-scale=1,minimum-scale=1.0,maximum-scale=1.0,user-scalable=no"/>
    <meta http-equiv="Cache-Control" content="no-siteapp"/>
    <link rel="stylesheet" type="text/css" href="${ctx}/static/h-ui/css/H-ui.min.css"/>
    <link rel="stylesheet" type="text/css" href="${ctx}/static/h-ui.admin/css/H-ui.admin.css"/>
    <link rel="stylesheet" type="text/css" href="${ctx}/lib/Hui-iconfont/1.0.8/iconfont.css"/>
    <link rel="stylesheet" type="text/css" href="${ctx}/static/h-ui.admin/skin/default/skin.css" id="skin"/>
<#--<link rel="stylesheet" type="text//css" href="${ctx}/datatables/css/dataTables.bootstrap.css"/>-->

</head>
<style>
    .table > tbody > tr > td {
        text-align: center;
    }

    th, td {
        white-space: nowrap;
    }
</style>

<body>
<div>
    <nav class="breadcrumb"><i class="Hui-iconfont">&#xe67f;</i> 首页 <span class="c-gray en">&gt;</span> 商城管理 <span
            class="c-gray en">&gt;</span> 首页轮播图管理 <span class="c-gray en">&gt;</span><span id="name"></span> <a
            class="btn btn-success radius r" style="line-height:1.6em;margin-top:3px"
            href="javascript:location.replace(location.href);" title="刷新"><i class="Hui-iconfont">&#xe68f;</i></a></nav>
    <form id="form-search" class="page-container">
        <div class="cl pd-5 bg-1 bk-gray mt-20">
            <span class="l">
                <a class="btn btn-primary radius" onclick="add('添加轮播图','${ctx}/home/rotation-chart/add/page')"
                   href="javascript:;"><i class="Hui-iconfont">&#xe600;</i> 添加轮播图</a>
            </span>
            <div class="mt-20">
                <div class="mt-20" style="margin-top: 45px">
                    <table class="table table-striped table-bordered table-hover dataTables-example">
                        <thead>
                        <tr class="text-c">
                            <th>ID</th>
                            <th>图片1</th>
                            <th>图片2</th>
                            <th>图片3</th>
                            <th>商品名称</th>
                            <th>排序值</th>
                            <th>更新日期</th>
                            <th>是否启用</th>
                            <th>操作</th>
                        </tr>
                        </thead>
                        <tbody>
                        <#list list as item>
                        <tr>
                            <td>${item.id}</td>
                            <td><img src="${item.picUrl1}" style="width: 80px;height: 60px"
                                     onerror="this.src='${ctx}/images/no-pic.gif'" alt="image"/></td>
                            <td><img src="${item.picUrl2}" style="width: 80px;height: 60px"
                                     onerror="this.src='${ctx}/images/no-pic.gif'" alt="image"/></td>
                            <td><img src="${item.picUrl3}" style="width: 80px;height: 60px"
                                     onerror="this.src='${ctx}/images/no-pic.gif'" alt="image"/></td>
                            <td>${item.item.title!'无'}</td>
                            <td>${item.sortOrder}</td>
                            <td>${item.updateTime}</td>
                            <td>
                                <#if item.state == 'INUSE'>
                                    <span class="label label-success radius td-status">启用</span>
                                <#else>
                                    <span class="label label-error radius td-status">禁用</span>
                                </#if>
                            </td>
                            <td>
                                <a style="text-decoration:none" class="ml-5" onClick="update('轮播图编辑','${item.id}','${item.sortOrder}',
                                        '${item.item.title!''}','${item.item.id!''}','${item.state}','${ctx}/home/rotation-chart/update/page')"
                                   href="javascript:;" title="编辑"><i class="Hui-iconfont">&#xe6df;</i></a>
                                <a style="text-decoration:none" class="ml-5" onClick="_delete(this,${item.id})"
                                   href="javascript:;" title="删除"><i class="Hui-iconfont">&#xe6e2;</i></a>
                            </td>
                        </tr>
                        </#list>
                        </tbody>
                    </table>
                </div>
            </div>
    </form>
</div>

<!--_footer 作为公共模版分离出去-->
<script type="text/javascript" src="${ctx}/js/jquery.min.js"></script>
<script type="text/javascript" src="${ctx}/js/bootstrap.min.js"></script>
<script type="text/javascript" src="${ctx}/lib/layer/2.4/layer.js"></script>
<#--<script type="text/javascript" src="${ctx}/datatables/js/dataTables.bootstrap.js"></script> <!--/_footer 作为公共模版分离出去&ndash;&gt;-->
<script type="text/javascript" src="${ctx}/datatables/js/jquery.dataTables.js"></script> <!--/_footer 作为公共模版分离出去-->

<script type="text/javascript">
    var currentCount = "${list?size!0}", limitCount = 5;
    $('.dataTables-example').DataTable({
        "scrollX": true,
        "bStateSave": true, //状态保存
        "bLengthChange": false,
        "bFilter": false,
        "iDisplayLength": 5,
        "aaSorting": [1, "asc"],//默认排序
        "aoColumnDefs": [
            {"orderable": false, "aTargets": [1,2, 3,8]}// 制定列不参与排序
        ],
    });


    /*添加*/
    function add(title, url) {
        if (currentCount >= limitCount) {
            layer.alert('轮播图内容数量已达上限', {title: '错误信息', icon: 0});
            return;
        }
        var index = layer.open({
            type: 2,
            title: title,
            content: url
        });
        layer.full(index);
    }


    var id, sortOrder, itemTitle, itemId, state;

    /*产品-编辑*/
    function update(title, _id, _sortOrder, _itemTitle, _itemId, _state, url) {
        id = _id;
        sortOrder = _sortOrder;
        itemTitle = _itemTitle;
        itemId = _itemId;
        state = _state;
        var index = layer.open({
            type: 2,
            title: title,
            content: url
        });
        layer.full(index);
    }

    /*内容-删除*/
    function _delete(obj, id) {
        layer.confirm('确认要删除ID为\'' + id + '\'的数据吗？', {icon: 0}, function (index) {
            var index = layer.load(3);
            $.ajax({
                type: 'DELETE',
                url: '${ctx}/home/rotation-chart/del/' + id,
                dataType: 'json',
                success: function (data) {
                    layer.close(index);
                    if (data.code != 200) {
                        layer.alert(data.msg, {title: '错误信息', icon: 2});
                        return;
                    }
                    refresh();
                    layer.msg('已删除!', {icon: 1, time: 1000});
                },
                error: function (XMLHttpRequest) {
                    layer.close(index);
                    layer.alert('数据处理失败! 错误码:' + XMLHttpRequest.status, {title: '错误信息', icon: 2});
                },
            });
        });
    }

    function msgSuccess(content){
        layer.msg(content, {icon: 1,time:3000});
    }
    function refresh() {
        location.reload()
    }
</script>
</body>
</html>
